Skip to content

Provide action limit configuration for each namespace #5229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Jan 25, 2023

Conversation

upgle
Copy link
Member

@upgle upgle commented May 3, 2022

Description

Currently, openwhisk has only the system limit shared by all namespaces. I have received requirements to set different limits for each namespace/user. So I propose a new feature for namespace limit.

3 types of limits

  • There are (1) system limits, (2) namespace default limits, (3) namespace limits.
    • (1) system limits: under no circumstances may this limit be exceeded.
    • (2) namespace default limits: use this limit value unless a limit has been set in the namespace.
    • (3) namespace limit: It can be set by the system administrator. This value cannot exceed the range of the system limit.

case1) Using default namespace limit

case1) Using namespace limit (for foo namespace)

Limit doc

You can set namespace limits with {namespace}/limits document just like any other existing setting.

{
  "concurrentInvocations": 100,
  "invocationsPerMinute": 100,
  "firesPerMinute": 100,
  "maxActionMemory": 128,
  "maxActionConcurrency": 400
  "maxActionLogs": 128,
  "maxParameterSize": "1 kb"
}

New namespace limit config

config key description
minActionMemory minimum action memory size for namespace
maxActionMemory maximum action memory size for namespace
minActionLogs minimum activation log size for namespace
maxActionLogs maximum activation log size for namespace
minActionTimeout minimum action time limit for namespace
maxActionTimeout maximum action time limit for namespace
minActionConcurrency minimum action concurrency limit for namespace
maxActionConcurrency maximum action concurrency limit for namespace
maxParameterSize maximum parameter size for namespace
maxPayloadSize maximum activation payload size for namespace
truncationSize activation truncation size for namespace

Related issue and scope

I didn't open new issue, but described the changes here.

My changes affect the following components

  • API
  • Controller
  • Tests
  • Documentation

Types of changes

  • Bug fix (generally a non-breaking change which closes an issue).
  • Enhancement or new feature (adds new functionality).
  • Breaking change (a bug fix or enhancement which changes existing behavior).

Checklist:

  • I signed an Apache CLA.
  • I reviewed the style guides and followed the recommendations (Travis CI will check :).
  • I added tests to cover my changes.
  • My changes require further changes to the documentation.
  • I updated the documentation where necessary.

@style95
Copy link
Member

style95 commented May 3, 2022

Nice!
Could you open another PR to add a POEM for this feature as well?
https://github.com/apache/openwhisk/tree/master/proposals

@upgle upgle changed the title [Proposal] Provide different action limits for different namespaces [Proposal] Provide action limit configuration for each namespace May 3, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 3, 2022

Codecov Report

Merging #5229 (9005a08) into master (9005a08) will not change coverage.
The diff coverage is n/a.

❗ Current head 9005a08 differs from pull request most recent head 28ade66. Consider uploading reports for the commit 28ade66 to get more accurate results

@@           Coverage Diff           @@
##           master    #5229   +/-   ##
=======================================
  Coverage   81.12%   81.12%           
=======================================
  Files         239      239           
  Lines       14192    14192           
  Branches      580      580           
=======================================
  Hits        11513    11513           
  Misses       2679     2679           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@upgle upgle added the wip label May 3, 2022
@@ -179,6 +178,8 @@ class InvokerReactive(
WhiskAction
.get(entityStore, actionid.id, actionid.rev, fromCache = actionid.rev != DocRevision.empty)
.flatMap(action => {
// action that exceed the system limit cannot be executed.
action.limits.checkSystemLimits()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiangpengcheng The code you shared is for checking the limit when creating an action.
In order to prevent execution by malicious modifications such as DB alteration, the invoker side verifies once more before invoking an action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it apply the new scheduler? e.g. when FunctionPoolConatinerProxy fetches the activation from memoryQueue's activation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It supports new scheduler.

Messages.sizeExceedsAllowedThreshold(MemoryLimit.memoryLimitFieldName, is.toMB.toInt, allowed.toMB.toInt)
}
}
}
Copy link
Contributor

@ningyougang ningyougang May 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with test case, can provide the opposite test case? e.g. allow create when memory is greater than maximum allowed namespace limit?

@@ -624,6 +626,30 @@ trait WhiskActionsApi extends WhiskCollectionAPI with PostActionActivation with
})
}

private def checkNamespaceAndSystemLimits(user: Identity, content: WhiskActionPut)(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be two separate functions? The context in which you check the set limits for a namespace are different from the context you check the system limits. You check against the system limits when creating the action or updating your namespace's configuration. When you check against the namespace's limit it would be on the execution path when an activation is occurring.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because updating the namespace limit configuration directly inserts/updates into the Couch DB, I've updated the code to fallback to the system limit if the namespace limit that exceeds the system limit.

So, namespace limits that can not exceed the system limit are checked when an action is created/invoked.

@upgle
Copy link
Member Author

upgle commented May 10, 2022

@style95 As the implementation continues to change, POEM has been added to this PR for consistency.
I will continue to update the PR content as well.

Nice!
Could you open another PR to add a POEM for this feature as well?
https://github.com/apache/openwhisk/tree/master/proposals

@style95
Copy link
Member

style95 commented May 10, 2022

According to this process, we need a separate PR to add a POEM along with this PR.
https://github.com/apache/openwhisk/blob/master/proposals/POEM-1-proposal-for-openwhisk-enhancements.md#procedures

@ningyougang
Copy link
Contributor

ningyougang commented May 12, 2022

If this pr: /pull/5229 merged.

Let's assume, user may want to use 3GB of memory for her action, but the system limit maybe 2GB currently.

  • Does openwhisk admin need to reconfigure his system limit (e.g. make system limit to a high value)?

    So openwhisk admin needs to adjust the system limit value to >=3GB?

  • As common user, he just changes the $namespace/limit document is enough?

    Has any check mechanism that when user changes the $namespace/limit document, namespace limit value can't be greater than system limit?

  • Has any extra work on wskadmin? e.g. Admin can use wskadmin can change the $namespace/limit document as well.

Have any influence for old action? e.g. user or admin may need some migration works.

@upgle
Copy link
Member Author

upgle commented May 12, 2022

@ningyougang

  • Does openwhisk admin need to reconfigure his system limit (e.g. make system limit to a high value)?
    So openwhisk admin needs to adjust the system limit value to >=3GB?

    • If the existing system limit was 2GB and you want to allocate up to 3GB, you need to raise the system limit and redeploy it. And because the namespace default limit is 2GB, existing users without a limit setting will use this limit.
  • Has any check mechanism that when user changes the $namespace/limit document, namespace limit value can't be greater than system limit?

    • If the namespace limit is greater than the system limit, it is lowered to the system limit.
  • Has any extra work on wskadmin? e.g. Admin can use wskadmin can change the $namespace/limit document as well.

    • Not yet. There is a plan to add it, but it seems to have to be created as a separate PR because there are a lot of changes in the PR.

@style95

According to this process, we need a separate PR to add a POEM along with this PR.
https://github.com/apache/openwhisk/blob/master/proposals/POEM-1-proposal-for-openwhisk-enhancements.md#procedures

I'm working on integrating with the new scheduler and improving backward compatibility. I'ill create a separate POEM PR as soon as it is completed.

@upgle
Copy link
Member Author

upgle commented May 16, 2022

Removed the POEM document file from this PR as it created a separate PR for POEM #5236.

@upgle upgle force-pushed the namespace-limit-config branch 2 times, most recently from 7de6e59 to ac42477 Compare May 26, 2022 14:56
@upgle upgle removed the wip label May 28, 2022
@upgle upgle changed the title [Proposal] Provide action limit configuration for each namespace Provide action limit configuration for each namespace May 28, 2022
Copy link
Member

@style95 style95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It generally looks good to me.

@@ -124,13 +129,13 @@ protected class ApacheBlockingContainerClient(hostname: String,

// Negative contentLength means unknown or overflow. We don't want to consume in either case.
if (contentLength >= 0) {
if (contentLength <= maxResponseBytes) {
if (contentLength <= maxResponse.toBytes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need toBytes here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Since maxResponse is a ByteSize type, it needs a cast.

    maxResponse: ByteSize,

} catch {
case _: Throwable =>
// Supports backwards compatibility for openwhisk that do not use the namespace default limit
ActivationEntityPayload(config.payload.max, config.payload.truncation)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

val int = the[DeserializationException] thrownBy s.read(JsNumber(2.5))
int.getMessage should include("limit must be whole number")
}
}
}

it should "reject bad limit values" in {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need this negative test case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scheme test based on the hardcoded limit value is no longer used and validation checks are performed based on user input at runtime.

@style95
Copy link
Member

style95 commented Jun 22, 2022

@upgle It seems it does not pass the unit test.
I kept rerunning the test but could not make it work.

@upgle upgle force-pushed the namespace-limit-config branch from 8b343d9 to 4222ceb Compare July 12, 2022 10:15
@upgle upgle force-pushed the namespace-limit-config branch from 4222ceb to 5442831 Compare July 25, 2022 02:24
Copy link
Member

@style95 style95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@style95 style95 requested a review from KeonHee August 2, 2022 06:40
@upgle upgle force-pushed the namespace-limit-config branch from ea4930b to fa46215 Compare August 2, 2022 10:46
@ningyougang
Copy link
Contributor

Need rebase

@upgle upgle force-pushed the namespace-limit-config branch from 0a312a4 to 0fbc5e8 Compare August 3, 2022 16:01
@upgle upgle force-pushed the namespace-limit-config branch from 8881b5e to 28ade66 Compare August 9, 2022 02:51
@style95 style95 merged commit 61ca4c8 into apache:master Jan 25, 2023
@style95
Copy link
Member

style95 commented Jan 25, 2023

merged as it's been so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants